<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
</head>
<body>
<div style="height: 20px"></div>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">设备管理</a>
        <a href="#">修改设备</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<form  action="" class="layui-form" id="equipment" onsubmit="return false" style="width:500px;padding-top: 5px">
    <input type="hidden" name="id" value="{$numberInfo.id}">
    <input type="hidden" name="old_number" value="{$numberInfo.number}">
    <div class="layui-form-item">
        <label class="layui-form-label">设备编号</label>
        <div class="layui-input-block">
            <input type="text" name="number" readonly value="{$numberInfo.number}" id="number" placeholder="设备编号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">学校</label>
        <div class="layui-input-block">
            <select name="school_id" id="school_id" style="width: 500px">
                <option value="">请选择学校</option>
                {foreach $school as $info}
                    <option value="{$info.school_id}" {if $info.school_id == $numberInfo.school_id} selected {/if}>{$info.school_name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">家长</label>
        <div class="layui-input-block">
            <select name="parent_id" id="parent_id" style="width: 500px">
                <option value="">请选择家长</option>
                {foreach $parent as $info}
                <option value="{$info.id}" {if $info.id == $numberInfo.parent_id} selected {/if}>{$info.phone}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">绑定类型</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="1" {if $numberInfo.school_id !=""} checked {/if} title="学校">
            <input type="radio" name="type" value="2" {if $numberInfo.parent_id !=""} checked {/if} title="家长">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学校批次号</label>
        <div class="layui-input-block">
            <input type="text" name="batch" value="{$numberInfo.batch}" id="batch" placeholder="批次号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">座位号</label>
        <div class="layui-input-block">
            <input type="text" name="serial_number" value="{$numberInfo.serial_number}" id="serial_number" placeholder="座位号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="update">立即修改</button>
            <button id="back" class="layui-btn layui-btn-primary">返回</button>
        </div>
    </div>
</form>
</body>
<script>
    $("#update").click(function(){
        if(!$("#serial_number").val()){
            layer.msg('设备序列号不能为空',{icon:5,time:2000});
            return;
        }
        $.ajax({
            url:"{:url('/equipment/updateEquipment')}",
            data:$("#equipment").serialize(),
            type:"post",
            dataType:"json",
            success:function(res){
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                }
            }
        });
    });
    $("#back").click(function () {
        window.history.go(-1);
    })
</script>
</html>